var leftLotto="";
var LtIndex=0;
function ClearColor()
{
	$(".rchange").removeClass("rchange");	
}
function ChangeRate(r,v)
{
	var old=$("#"+r).text();
	if(old!=v)
	{
		$("#"+r).parent().addClass("rchange");		
	}
	$("#"+r).text(v);
}
function RefLotto()
{
	$.get("op.php?op=member&fp=gameopen&gtype="+$("#game_lotto").attr("gametype"),null,function(r){
			if(leftLotto!="" && leftLotto!=r)
			{
				$("#myOpenSound").jPlayer('play');
				parent.leftFrame.location.reload();		
			}
			leftLotto=r;
			$("#game_lotto").html(r);
		})	
	window.setTimeout("RefLotto()",20000);
}
$(document).ready(function(e) {
	if(page_b!="6-1" && playtype!="rc")
	{
		var f=($.cookie("sub_type")=="1"?"a":"b");
		$("#sub_"+f).addClass("btn");
		if(f=="a") ChangeSelType(1);
	}
	if(page_b!=""){
		RefRate();
		window.setInterval("RefRate()",15000);
		$("#RefTimeV").text("15秒");
		window.setInterval("StartRefTime()",1000);
		$("input[type=reset]").bind("click",function(e1){
			ClearSel();
		});
		$("#btnBet2").bind("click",function(e1){
			var v=$("#changeMoney").val();
			if(v=="") 
			{
				alert("请输入金额！");return false;	
			}
			$(".round-table2 input").each(function(index, element) {
				if(element.value=="*")
					$(element).val(v)	
				else if(element.className=="selcolor")   
					$(element).val(v)
			});	
			$("#changeMoney").val("");		
		});
		$("#newForm").submit(function(r){
			if($("#sub_a").attr("class")=="btn")
			{
				var v=$("#changeMoney").val();
				$(".round-table2 input").each(function(index, element) {
					if(element.value=="*")
						$(element).val(v)	   
				});	
				$("#changeMoney").val("");		
			}
		});
		$(".rate").bind("click",function(){
			if(typeof($(this).attr("href"))!="undefined")
			{
				if(page_b=="start")
					parent.leftFrame.location.href=$(this).attr("href")+"&rate="+$(this).text()+"&disk="+$("#select_disk").val();
				else
					parent.leftFrame.location.href="op.php?op=member&"+$(this).attr("href")+"&rate="+$(this).text()+"&disk="+$("#select_disk").val();		
			}
		});
	}
	if(gametype>=11)
	{
		$("#OpenTimePanel").show();
		timestap_open=timestap+60;	
		RefOpenTime();	
	}
	RefEndTime();
	RefLotto();
	$("#myContent").jPlayer({
		ready: function () {
			$(this).jPlayer("setMedia", {
				mp3:"sound/1.mp3"
			});
		},
		swfPath:"sound/",
		supplied: "mp3"
	});
	$("#myOpenSound").jPlayer({
		ready: function () {
			$(this).jPlayer("setMedia", {
				mp3:"sound/in3.mp3"
			});
		},
		swfPath:"sound/",
		supplied: "mp3"
	});
	if(gametype>=11 && gametype<=15)
	{
		$("#RightSM").load("/op.php?op=member_3d&fp=game_sm&gametype="+gametype+"&open="+odate);
		$("#BottomLT").load("/op.php?op=member_3d&fp=game_lt&palygroup="+playtype+"&open="+odate+"&gametype="+gametype,null,function(r){
			$(".disClc").bind("click",function(e){
				$("#lt_tr_"+LtIndex).hide();
				$("#lt_tr_"+$(this).attr("tag")).show();
				LtIndex=$(this).attr("tag");
				$(".disClcSel").removeClass("disClcSel");
				$(this).addClass("disClcSel");
				//$(document).scrollTop(999);
			});
			$(".disClc").eq(0).trigger("click");
		});	
	}
	else if(gametype>=20 && gametype<=24)
	{
		$("#RightSM").load("/op.php?op=member_5h&fp=game_sm&gametype="+gametype+"&open="+odate);
		$("#BottomLT").load("/op.php?op=member_5h&fp=game_lt&palygroup="+playtype+"&open="+odate+"&gametype="+gametype,null,function(r){
			$(".disClc").bind("click",function(e){
				var id=$(this).attr("id").replace("chgBV","");
				$("#chgBallAreaStr").html(chgBallArr[id]);
				$(".disClcSel").removeClass("disClcSel");
				$(this).addClass("disClcSel");
				$("#chgBallAreaStr td").each(function(index, element) {
                    if(index%2==1)
						element.style.backgroundColor="#E7EBEF";	
                });
				//$(document).scrollTop(999);
			});
			$(".disClc").eq(0).trigger("click");
		});	
	}
});
function check_box(num)
{
	if(gametype>=20 && gametype<=24)
		$("#RightSM").load("/op.php?op=member_5h&fp=game_sm&gametype="+gametype+"&number="+num+"&open="+odate);
	else if(gametype>=11 && gametype<=15)
		$("#RightSM").load("/op.php?op=member_3d&fp=game_sm&gametype="+gametype+"&number="+num+"&open="+odate);	
}
function ClearSel()
{
	$(".selcolor").removeClass("selcolor");	
}
function ChangeSelType(t)
{
	if(playtype!="rc") $.cookie("sub_type",t);
	if(t==1)
	{
		$("#sub_a").addClass("btn");
		$("#sub_b").removeClass("btn");
		$(".round-table2 input[type=text]").each(function(index, element) {
        	var obj=$(element);
			obj.val("");
			obj.hide();
			obj.parent().addClass("selinput");	   
        });	
		$(".selinput").bind("click",function(e){
			var iobj=$(this).find("input");
			var selnum=$(this).parent().parent().parent().attr("selnum");
			if(typeof(selnum)=="undefined") selnum=3;
			if(iobj.val()=="*")
			{
				iobj.val("");
				$(this).removeClass("selcolor");
				if(selnum>=2)
				{
					var pobj=$(this).prev();
					pobj.removeClass("selcolor");
					if(selnum==3)
						pobj.prev().removeClass("selcolor");	
				}
			}
			else{
				iobj.val("*");
				$(this).addClass("selcolor");
				if(selnum>=2)
				{
					var pobj=$(this).prev();
					pobj.addClass("selcolor");
					if(selnum==3)
						pobj.prev().addClass("selcolor");
				}
			}
		});
		$("#btnBet2").hide();
	}
	else
	{
		$("#sub_b").addClass("btn");
		$("#sub_a").removeClass("btn");
		ClearSel();
		$(".selinput").unbind("click");
		$(".round-table2 input[type=text]").each(function(index, element) {
        	var obj=$(element);
			obj.val("");
			obj.show();
			obj.parent().removeClass("selinput");	   
        });	
		$("#btnBet2").show();	
	}
}
function StartRefTime()
{
	var v=parseInt($("#RefTimeV").text().replace("秒",""));
	v--;
	if(v==0) v=15;
	$("#RefTimeV").text(v+"秒");	
}
function RefEndTime()
{
  	timediff = timestap;
  	days = Math.floor(timediff / (60 * 60 * 24));
	timediff -= days * (60 * 60 * 24);
	hours = Math.floor(timediff / (60 * 60));
	timediff -= hours * (60 * 60);
	mins = Math.floor(timediff / (60));
	timediff -= mins * (60);
	secs = Math.floor(timediff);

    str = "";
    if (days > 0 ) str += "<b>" + days + "</b> 天 ";
    if (hours > 0) str += "<b>" + hours + "</b> 时 ";  // 
    if (mins > 0) str += "<b>" + d2(mins) + "</b> 分 ";  // 
    str += "<b>" + d2(secs) + "</b> 秒"; //
    $("#EndTimeSpan").html(str); 
    timestap-=1;

	if(days==0 && hours==0 && mins==0 && secs<=10)
		$("#myContent").jPlayer('play');
    if (days==0 && hours==0 && mins==0 && secs==0) {
        location.reload();
    }
	else
		setTimeout("RefEndTime()",1000)
}
function RefOpenTime()
{
  	timediff = timestap_open;
  	days = Math.floor(timediff / (60 * 60 * 24));
	timediff -= days * (60 * 60 * 24);
	hours = Math.floor(timediff / (60 * 60));
	timediff -= hours * (60 * 60);
	mins = Math.floor(timediff / (60));
	timediff -= mins * (60);
	secs = Math.floor(timediff);

    str = "";
    if (days > 0 ) str += "<b>" + days + "</b> 天 ";
    if (hours > 0) str += "<b>" + hours + "</b> 时 ";  // 
    if (mins > 0) str += "<b>" + d2(mins) + "</b> 分 ";  // 
    str += "<b>" + d2(secs) + "</b> 秒"; //
    $("#OpenTimeSpan").html(str); 
    timestap_open-=1;
	
    if (days==0 && hours==0 && mins==0 && secs==0) {
        location.reload();
    }
	else
		setTimeout("RefOpenTime()",1000)
}
function d2(v)
{
	return (v<=9?'0':'')+v;	
}
